﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for CartItem
/// </summary>
public class CartItem : IEquatable<CartItem>
{
    private int _quantity;

    public int Quantity
    {
        get { return _quantity; }
        set { _quantity = value; }
    }
    private int _pdID;

    public int PdID
    {
        get { return _pdID; }
        set {
            _product = null;
            _pdID = value; }
    }
    private Product _product;

    public Product Product
    {
        get
        {
            //tao ra doi tuong neu == null
            if (_product == null)
            {
                _product = new Product(_pdID);
            }
            return _product;
        }
        set { _product = value; }
    }

    public String Description{
        get
        {
            return Product.PdDescription;
        }        
    }

    public String ProductName
    {
        get 
        {
            return Product.PdName;
        }
    }
 
    public String Image
    {
        get
        {
            return Product.PdImage;
        }
    }

    public decimal UnitPrice
    {
        get
        {
            return Product.PdPrice;
        }
    }

    public decimal TotalPrice
    {
        get
        {
            return UnitPrice * Quantity;
        }
    }
    //constructor
    public CartItem(int _productID)
    {
        this._pdID = _productID;
    }

    public bool Equals(CartItem item)
    {
        return item.PdID == this.PdID;
    }
}
